/**
 * @param {View} shell
 * @constructor
 * @extends BaseMediator
 */
function ExifMediator(shell)
{
	"use strict";

	this.init(shell, '#camera');

	/** @type {ExifMediator} */
	var _this = this;

	/**
	 * Called whenever a new photo is loaded
	 * @return {ExifMediator}
	 */
	this.update = function()
	{
		if (_this.visible && _this.enabled) { layout(); }
		return _this;
	};

	/**
	 * Called when toolbar button clicked
	 * @return {ExifMediator|BaseMediator}
	 */
	this.show = function()
	{
		if (_this.enabled && Session.photo != null) { layout(); }
		return _this.base.show.call(_this);
	};

	function layout()
	{
		/** @type {Photo} */
		var p = Session.photo;

		if (p.exif == null) { p.loadExif(layout); return; }

		var $s = $('<div>').addClass('settings');

		addSetting($s, p.exif.lens.aperture, '<em>f</em>/{0}');
		addSetting($s, p.exif.exposure.time, '{0}s');
		addSetting($s, p.exif.exposure.compensation, '{0} EV');
		addSetting($s, p.exif.settings.ISO, 'ISO {0}');
		addSetting($s, p.exif.lens.focalLength, 'at {0}mm');

		var camera = p.exif.camera.model;
		if (p.exif.lens.model) { camera = p.exif.lens.model + '<br/>on a ' + camera; }

		_this.content.empty()
			.append($('<div>').addClass('tools')
				.append($('<h4>').html('Captured with'))
				.append($('<p>').html(camera))
				.append($('<h4>').html('Developed with'))
				.append($('<p>').html(p.exif.software))
			)
			.append($s);

		// set busy in View.photoChanging()
		_this.busy(false);
	}

	/**
	 * @param {jQuery} el
	 * @param {String|Number} value
	 * @param {String} format
	 */
	function addSetting(el, value, format)
	{
		if (value) { el.append($('<div>').html(format.replace('{0}', value))); }
	}

}
ExifMediator.inherit(BaseMediator);
